<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/include/taglibs.jsp"%>
<script type="text/javascript">

$(document).ready(function(){

});

//데이터 저장
function submitData(){

	$("input[name='admin_nos']").each(function(){
		if(""==$(this).val()){
			$(this).parent().parent().remove();
		}else{
			$(this).val($(this).val().split("-").join(""));
		}
	});
	
	$.ajax({
		url: <c:if test="${'U'==udt }">"./updateAdmin.do"</c:if><c:if test="${'U'!=udt }">"./insertAdmin.do"</c:if>,
		dataType: "json",
		data:$("#frm").serialize(),
		success : function (json){
			if("0"==json.returnCd){
				showMsg("저장되었습니다");
				<c:if test="${'U'==udt }">
				location.href="./udtUsr.do?adm_seq=${param.adm_seq}";
				</c:if>
				<c:if test="${'U'!=udt }">
				location.href="./admList.do";
				</c:if>
				
				
			}else{
				showMsg("같은번호로 데이터가 있습니다");
			}
		},
		error : function(error){
			alert('저장에 실패하였습니다\n'+error);
		}
	});
}
function goList(){
	location.href="./admList.do";
}
function getEnc(){
	if(window.hwInfo){
		$("#enc").val(window.hwInfo.getInfo());	
	}
}

function showMsg(msg){
	if(window.hwInfo){
		$("#enc").val(window.hwInfo.showMsg(msg));	
	}else{
		alert(msg);
	}
}

var addUsr =1;
function addHp(){
	addUsr++;
	var html= "<tr id=\"hp"+addUsr+"\">"+
	"	<td height=\"25\" class=\"class_admin_table_head\" width=\"100\""+
	"		align=\"center\">&nbsp;</td>"+
	"	<td height=\"25\" colspan=\"3\" class=\"class_admin_table_blank\">&nbsp;&nbsp;"+
	"		<input type=\"text\" name=\"admin_nos\" size=\"30\" maxlength=\"125\" value=\"\" >"+
	"		<button onclick=\"$(this).parent().parent().remove();return false;\">삭제</button>"+
	"	</td>"+
	"</tr>";
		
	$("#hp").after(html);
}

</script>

<form action="./insertAdmin.do" id="frm" name="frmData" method="post">
	<input name="adm_seq" value="${param.adm_seq }" type="hidden"/>
업소정보
	<table width="700" border="0" cellspacing="1" cellpadding="2"
		class="class_admin_table">
		<tr>
			<td height="25" class="class_admin_table_head" width="100"
				align="center"><b>업종</b></td>
			<td height="25" class="class_admin_table_blank">&nbsp;&nbsp;
				<select name="type">
					<option value="">선택하세요</option>
	<c:if test="${cd1List !=null && fn:length(cd1List)>0 }">
		<c:forEach var="cd" items="${cd1List}" varStatus="status">
				<option value="${cd.code_no }" <c:if test="${map.type==cd.code_no }">selected="selected"</c:if>>${cd.code_nm }</option>
		</c:forEach>
	</c:if>
				</select>
			</td>
			<td height="25" class="class_admin_table_head" width="100"
				align="center"><b>업소명</b></td>
			<td height="25" class="class_admin_table_blank">&nbsp;&nbsp;
				<input type="text" name="company" size="30" maxlength="25" value="${map.company }">
			</td>
		</tr>
		<tr>
			<td height="25" class="class_admin_table_head" width="100"
				align="center">사용료</td>
			<td height="25" class="class_admin_table_blank">&nbsp;&nbsp;
				<input type="text" name="pay_use" size="30" maxlength="125" value="${map.pay_use }">
			</td>
			<td height="25" class="class_admin_table_head" width="100"
				align="center">조회구분</td>
			<td height="25" class="class_admin_table_blank">&nbsp;&nbsp;
				<label>
				<input type="checkbox" name="roll1" value="Y" <c:if test="${'Y'==map.roll1 }">checked="checked"</c:if>>
				조회
				</label>
				<label> 
				<input type="checkbox" name="roll2" value="Y" <c:if test="${'Y'==map.roll2 }">checked="checked"</c:if>>
				쓰기
				</label>
				<label> 
				<input type="checkbox" name="roll3" value="Y" <c:if test="${'Y'==map.roll3 }">checked="checked"</c:if>>
				삭제
				</label>
				<div style="display: none;">
					<label> 
					<input type="checkbox" name="roll4" value="Y" <c:if test="${'Y'==map.roll4 }">checked="checked"</c:if>>
					임시
					</label>
				</div>
			</td>
		</tr>
<c:if test="${'U'!=udt }">
		<tr id="hp">
			<td height="25" class="class_admin_table_head" width="100"
				align="center">
				전화번호
			</td>
			<td height="25" colspan="3" class="class_admin_table_blank">&nbsp;&nbsp;
				<input type="text" name="admin_nos" size="30" maxlength="125" value="" >
				<button onclick="addHp();return false;">추가</button>
			</td>
		</tr>

</c:if>
	<c:if test="${admHp !=null && fn:length(admHp)>0 }">
		<c:forEach var="data" items="${admHp}" varStatus="stat">
		<tr <c:if test="${stat.index == 0 }">id="hp"</c:if>>
			<td height="25" class="class_admin_table_head" width="100"
				align="center">
				<c:if test="${stat.index == 0 }">전화번호</c:if>
				<c:if test="${stat.index != 0 }">&nbsp;</c:if>
			</td>
			<td height="25" colspan="3" class="class_admin_table_blank">&nbsp;&nbsp;
				<input type="text" name="admin_nos" size="30" maxlength="125" value="<c:if test="${fn:length(data.admin_no)==11 }">${fn:substring(data.admin_no,0,3) }-${fn:substring(data.admin_no,3,7) }-${fn:substring(data.admin_no,7,11) }</c:if><c:if test="${fn:length(data.admin_no)==10 }">${fn:substring(data.admin_no,0,3) }-${fn:substring(data.admin_no,3,6) }-${fn:substring(data.admin_no,6,10) }</c:if><c:if test="${fn:length(data.admin_no)!=10 && fn:length(data.admin_no)!=11 }">${data.admin_no }</c:if>" >
				<c:if test="${stat.index == 0 }">
					<button onclick="addHp();return false;">추가</button>				
				</c:if>
				<c:if test="${stat.index != 0 }">
					<button onclick="$(this).parent().parent().remove();return false;">삭제</button>				
				</c:if>

			</td>
		</tr>

		</c:forEach>
	</c:if>
	
	

	</table>
</form>

<button onclick="submitData();">저장</button>
<button onclick="goList();">목록</button>